﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Fcom.VNInsurance.Web.Models;
using Fcom.VNInsurance.Web.CultureHelper;
using System.IO;
namespace Fcom.VNInsurance.Web.Controllers
{
    public class LayoutHelperController : CultureHelper.CultureController
    {
        //
        // GET: /LayoutHelper/
        VNInsuranceDataContext db = new VNInsuranceDataContext();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult ReadContentFolder()
        {
            string serverPath = Server.MapPath("~/Content");
            DirectoryInfo d = new DirectoryInfo(serverPath);
            List<SpeFolder> listf = new List<SpeFolder>();
            foreach (DirectoryInfo ff in d.GetDirectories())
            {
                SpeFolder a = new SpeFolder();
                a.FullName = ff.FullName;
                a.Name = ff.Name;
                if (ff.GetFiles().Count() > 0 || ff.GetDirectories().Count() > 0)
                    a.hasFiles = true;
                listf.Add(a);
            }
            return PartialView(listf);
        }
        public ActionResult CustomerInfo()
        {
            Fcom.IDLib.SaveMoneyID.AccountsynClient accClient = new Fcom.IDLib.SaveMoneyID.AccountsynClient();
           Fcom.IDLib.SaveMoneyID.FullUserInfo userinfo = accClient.getUserInfo(User.Identity.Name);
            accClient.Close();
            return PartialView(userinfo);
        }
        public ActionResult NavGeneral()
        {


            var langcats = db.ProductCatLangs.Where(l => l.LangID == Request.Cookies["_culture"]["lang"]);
            Dictionary<int, IEnumerable<Fcom.VNInsurance.Web.Models.ProductLang>> List = new Dictionary<int, IEnumerable<Fcom.VNInsurance.Web.Models.ProductLang>>();
            foreach (var cat in langcats)
            {
                //var products = from p in db.Products where p.CatID == cat.CatID select p;
                var products = from p in db.ProductLangs where p.LangID == Request.Cookies["_culture"]["lang"] && p.Product.CatID == cat.CatID select p;
                //IEnumerable<Fcom.VNInsurance.Web.Models.ProductLang> .ProductLangs.Where(m => m.LangID == Session["_culture"])
                List.Add(cat.CatID, products);
            }
            ViewBag.LangProducts = List;
            return PartialView(langcats);
        }
        public ActionResult NavLang()
        {
            var langs = db.Languages;
            return PartialView(langs);
        }
        public ActionResult NavLogin()
        {
            return PartialView();
        }
        public ActionResult NavNewsCat()
        {
            var newscat = db.NewsCategories;
            return PartialView(newscat);
        }
        public ActionResult NavProductCat()
        {
            var ProductCats = db.ProductCats;
            return PartialView(ProductCats);
        }
        public ActionResult NavProductBottom()
        {
            var sxml = db.MenuLangs.Where(m => m.LangID == Request.Cookies["_culture"]["lang"] && m.Menu.MenuPosID == 1);
            return PartialView(sxml);
        }
        public ActionResult BottomFeedXML()
        {
            
            return PartialView();
        }
        public ActionResult VNBBottomFeedXML()
        {

            return PartialView();
        }

        public ActionResult LoggedPart()
        {
            Fcom.IDLib.SaveMoneyID.AccountsynClient client = new IDLib.SaveMoneyID.AccountsynClient();
            var fullinfo = client.getUserInfo(User.Identity.Name);
            return PartialView(fullinfo);
        }
        public ActionResult TVsmfeedxml()
        {

            return PartialView();
        }
    }
}
